package com.zy.controller;

import com.zy.Vo.InboundVo;
import com.zy.Vo.ResultVo;
import com.zy.pojo.Inbound;
import com.zy.service.InboundService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;

@RestController
@RequestMapping("/inbound")
public class InboundController {
    @Resource
    private InboundService inboundService;
    @GetMapping("/list")
    public Object getInboundList() {
        return inboundService.getInboundList();
    }
    @GetMapping("/pagelist/{pageNo}/{pageSize}")
    public ResultVo geInboundPageList(@PathVariable Integer pageNo, @PathVariable Integer pageSize, InboundVo inboundVo){
        return ResultVo.sucess(inboundService.getPageInboundList(pageNo,pageSize,inboundVo));
    }
    @PostMapping("/inboundadd")
    public ResultVo getGoodsAdd(@RequestBody Inbound inbound, HttpSession session) {
        try {
            inbound.setInboundDate(new Date());
            inboundService.getInboundAdd(inbound);
            return ResultVo.sucess("入库商品添加成功!!!");
        } catch (Exception e) {
            return ResultVo.fail("入库商品添加失败", e);//打印错误日志
        }
    }
    @GetMapping("/inbounddel/{id}")
    public  ResultVo del(@PathVariable String id) {
        try {
            inboundService.getInboundDelete(Integer.parseInt(id));
            return ResultVo.sucess("入库商品删除成功!!!");
        } catch (Exception e) {

            return ResultVo.fail("入库商品删除失败!!!", e);
        }
    }
    @GetMapping("/inpolist")
    public ResultVo getInboundPoList(){
        return ResultVo.sucess(inboundService.getInboundPoList());
    }

    @PostMapping("/deliveredaddRk")
    public ResultVo getHousedAdd(@RequestBody Inbound inbound, HttpSession session){
        try{
            inboundService.getInboundDeAdd(inbound);
            inboundService.getInboundDelete(inbound.getId());
            return ResultVo.sucess("出库商品成功!!!");
        }catch (Exception e){
            return ResultVo.fail("出库商品失败",e);//打印错误日志
        }
    }
    }
